<?php
class db
{
	var $link_id;
	
	function __construct()
	{
	$this->connect(DB_HOST,DB_USER,DB_PWD,DB_NAME);
	}
	
	function connect($db_host,$db_user,$db_pwd,$db_name='',$db_charset='UTF8')
	{
		    $this->link_id=mysql_connect($db_host,$db_user,$db_pwd) or die("连接数据库失败");
		    mysql_select_db($db_name,$this->link_id) or die("选择数据库失败");
		    mysql_query("set names ".$db_charset) or die("初始化编码失败");
	}
	
	function query($sql)
	{
		if($query=mysql_query($sql,$this->link_id))
			return $query;
		else
		   return false;
	}
	
	function getonerow($sql)
	{
		$res=$this->query($sql);
		if($res)
		     return mysql_fetch_assoc($res);
		else
		     return false;
	}
	
	function getlist($sql)
	{
		$res=$this->query($sql);
		if($res)
		{
			$arr=array();
			while($row=mysql_fetch_assoc($res))
			{
				$arr[]=$row;
			}
			return $arr;
		}
		else
		    return false;
	}
	
	function getrowsnum($sql)
	{
		$query=$this->query($sql);
		return mysql_num_rows($query);
	}
	
	function getinsertid()
	{
		return mysql_insert_id($this->link_id);
	}
}

?>